var t = require("../../../@babel/runtime/helpers/typeof"), e = require("../../../mycomponent/yz_pay/yz_pay"), a = getApp();

Page({
    behaviors: [ e ],
    data: {
        language: "",
        totalAmonut: "",
        totalNumber: "",
        totalMember: [],
        clockInNum: 0,
        clockFirstShow: !1,
        clockFirstMember: {},
        luckyMemberShow: !1,
        continueMember: {},
        continueMemberShow: !1,
        notClockInNum: 0,
        btnStatus: "",
        amount: "1",
        actionSheetShow: !1,
        actionSheetItemsData: [],
        clockin_title: "早起打卡",
        share_title: "",
        share_icon: "",
        share_desc: "",
        clock_begintime: "",
        clock_endtime: "",
        ios_virtual_pay: !1,
        forbidden: !0
    },
    onLoad: function(t) {
        this.checkrouter();
        try {
            var e = wx.getStorageSync("ios_virtual_pay");
            e && this.setData({
                ios_virtual_pay: e
            });
        } catch (t) {
            console.log(t);
        }
    },
    checkrouter: function() {
        try {
            var e = function() {
                for (var t = wx.getStorageSync("yz_basic_info"), e = t.popularize_page.mini.vue_route, a = 0; a < e.length; a++) if ("ClockPunch" == e[a]) return console.log(t.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: t.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
            }();
            if ("object" === t(e)) return e.v;
        } catch (t) {
            console.log(t);
        }
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {
        wx.showShareMenu({
            withShareTicket: !1,
            menus: [ "shareAppMessage", "shareTimeline" ]
        }), this._initData(), this._getTodayPay(), this._getTodayClockOn(), this._getCurrentPayStatus(), 
        this._getPayData(), this._getClockin();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareTimeline: function() {
        return {
            title: this.data.share_title,
            imageUrl: this.data.share_icon
        };
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share_title,
            imageUrl: this.data.share_icon
        };
    },
    _getTodayPay: function() {
        var t = this, e = a.getNetAddresss("plugin.clock-in.api.clock-in.get-today-pay-data");
        a._getNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                1 == a.result && t.setData({
                    totalAmonut: a.data.today_pay_amount,
                    totalNumber: a.data.today_pay_num,
                    totalMember: a.data.today_pay_member
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _getTodayClockOn: function() {
        var t = this, e = a.getNetAddresss("plugin.clock-in.api.clock-in.get-today-clock-data");
        a._getNetWork({
            url: e,
            success: function(e) {
                var n = e.data;
                1 == n.result && (a._isTextEmpty(n.data.clock_firat_member) ? t.setData({
                    clockFirstShow: !1
                }) : t.setData({
                    clockFirstShow: !0,
                    clockFirstMember: n.data.clock_firat_member
                }), a._isTextEmpty(n.data.reward_lucky_member) ? t.setData({
                    luckyMemberShow: !1
                }) : t.setData({
                    luckyMemberShow: !0,
                    luckyMember: n.data.reward_lucky_member
                }), a._isTextEmpty(n.data.clock_continuity_member) ? t.setData({
                    continueMemberShow: !1
                }) : t.setData({
                    continueMemberShow: !0,
                    continueMember: n.data.clock_continuity_member
                }), t.setData({
                    clockInNum: n.data.clock_in_num,
                    notClockInNum: n.data.not_clock_in_num
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _getCurrentPayStatus: function() {
        var t = this, e = a.getNetAddresss("plugin.clock-in.api.clock-in.get-member-pay-status");
        a._getNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                1 == a.result ? (t.setData({
                    amount: a.data.amount,
                    btnStatus: a.data.status
                }), t.initBtnView(a.data)) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    initBtnView: function(t) {
        switch (t.status) {
          case -1:
          case 0:
            this.setData({
                message: "支付" + this.data.amount + (this.data.language["元"] ? this.data.language["元"] : "元") + "参与挑战"
            });
            break;

          case 1:
            this.setData({
                forbidden: !0,
                cutDownTime: this.getCutDownTime(t)
            }), this._countDown();
            break;

          case 2:
            this.setData({
                message: "打卡"
            });
            break;

          case 3:
          case 4:
            this.setData({
                forbidden: !0,
                cutDownTime: this.getCutDownTime(t)
            }), this._countDown();
        }
    },
    _countDown: function() {
        if (!this.data.forbidden) return !1;
        var t = new Date().getTime(), e = this.data.cutDownTime, a = null;
        if (e - t > 0) {
            var n = (e - t) / 1e3, o = parseInt(n / 86400), i = parseInt(n % 86400 / 3600), c = parseInt(n % 86400 % 3600 / 60), s = parseInt(n % 86400 % 3600 % 60);
            a = {
                day: this._timeFormat(o),
                hou: this._timeFormat(i),
                min: this._timeFormat(c),
                sec: this._timeFormat(s)
            };
        } else a = {
            day: "00",
            hou: "00",
            min: "00",
            sec: "00"
        };
        this.setData({
            message: "倒计时" + a.day + "天" + a.hou + "时" + a.min + "分" + a.sec + "秒"
        }), e - t < 0 ? (this.setData({
            forbidden: !1
        }), this._getTodayClockOn(), this._getCurrentPayStatus()) : setTimeout(this._countDown.bind(this), 1e3);
    },
    _timeFormat: function(t) {
        return t < 10 ? "0" + t : t;
    },
    getCutDownTime: function(t) {
        var e = parseInt(t.current_time), a = parseInt(t.start_time), n = 0;
        return e < a && (n = a), 1e3 * n;
    },
    _getPayData: function() {
        var t = this, e = a.getNetAddresss("plugin.clock-in.api.clock-in-pay.get-pay-button");
        a._getNetWork({
            url: e,
            success: function(e) {
                var n = e.data;
                if (1 == n.result) {
                    var o = n.data.buttons;
                    if (!a._isTextEmpty(o) && o.length > 0) {
                        for (var i = [], c = 0; c < o.length; c++) i.push({
                            name: o[c].name,
                            openType: o[c].value
                        });
                        t.setData({
                            actionSheetItemsData: i
                        });
                    }
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    initPayCallBack: function(t) {
        switch (t) {
          case 1:
          case 55:
            this.weChatPay();
            break;

          case 3:
            this.balancePay();
            break;

          case 28:
            this.balanceHjPay();
        }
    },
    weChatPay: function() {
        this.payPost(1);
    },
    balancePay: function() {
        this.payPost(3);
    },
    balanceHjPay: function() {
        this.payPost(28);
    },
    payPost: function(t) {
        var e = this, n = a.getNetAddresss("plugin.clock-in.api.clock-in-pay.run-clock-pay");
        n += "&pay_method=" + t, n += "&amount=" + this.data.amount, n += "&client_type=2", 
        a._getNetWork({
            url: n,
            success: function(a) {
                var n = a.data;
                1 == n.result ? e.rechargePay(t, n, n.data.ordersn, "clock") : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    clokinBtnCallBack: function() {
        if (this.data.ios_virtual_pay) return wx.showModal({
            title: "提示",
            content: "十分抱歉，由于相关规定，你暂时无法在这里充值！",
            confirmText: "知道了",
            showCancel: !1,
            success: function(t) {
                console.log(t);
            }
        }), !1;
        switch (this.data.btnStatus) {
          case -1:
          case 0:
            this.setData({
                actionSheetShow: !0
            });
            break;

          case 1:
            break;

          case 2:
            this.postClockIn();
            break;

          case 3:
            this.setData({
                actionSheetShow: !0
            });
        }
    },
    postClockIn: function() {
        var t = this, e = a.getNetAddresss("plugin.clock-in.api.clock-in.run-clock-in");
        a._getNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                1 == a.result ? (t._getCurrentPayStatus(), t._getTodayPay(), wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    actionbtn: function(t) {
        var e = t.detail.openType;
        this.initPayCallBack(e);
    },
    onClose: function() {
        this.setData({
            actionSheetShow: !1
        });
    },
    goClockPunchRule: function() {
        wx.navigateTo({
            url: "/packageA/member/ClockPunchRule/ClockPunchRule"
        });
    },
    goClockPunchRecord: function() {
        wx.navigateTo({
            url: "/packageA/member/ClockPunchRecord/ClockPunchRecord"
        });
    },
    _getClockin: function() {
        var t = this, e = a.getNetAddresss("plugin.clock-in.api.clock-in.get-set");
        a._getNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                if (1 == a.result) t.setData({
                    clockin_title: a.data.plugin_name,
                    share_title: a.data.share.share_title,
                    share_icon: a.data.share.share_icon,
                    share_desc: a.data.share.share_desc,
                    clock_begintime: a.data.clock_time.starttime,
                    clock_endtime: a.data.clock_time.endtime
                }); else if (0 == a.data.is_clock_in) {
                    var n = a.data.plugin_name;
                    wx.showModal({
                        title: "提示",
                        content: "".concat(n, "已禁用"),
                        showCancel: !1,
                        success: function(t) {
                            t.confirm && wx.redirectTo({
                                url: "/packageG/member_v2/member_v2"
                            });
                        }
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _initData: function() {
        this.setData({
            totalAmonut: "",
            totalNumber: "",
            totalMember: [],
            clockInNum: 0,
            clockFirstShow: !1,
            clockFirstMember: {},
            luckyMemberShow: !1,
            continueMember: {},
            continueMemberShow: !1,
            notClockInNum: 0,
            btnStatus: "",
            amount: "1",
            actionSheetShow: !1,
            actionSheetItemsData: [],
            clockin_title: "早起打卡",
            share_title: "",
            share_icon: "",
            share_desc: "",
            clock_begintime: "",
            clock_endtime: ""
        });
    }
});